package com.hfdg.coordination.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hfdg.prototype.base.utils.TimeUtils;
import com.hfdg.coordination.mapper.CoordFeedbackMapper;
import com.hfdg.coordination.entity.CoordFeedback;
import com.hfdg.coordination.service.CoordFeedbackService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.UUID;

/**
 * @ClassName CoordFeedbackServiceImpl
 * @Description CoordFeedback,主要对CoordFeedback类型数据的业务服务操作实现类
 * @Company 会飞的锅工作室
 * @Author yuelh
 * @Email 18695867679@163.com
 * @Date 2020/05/18 07:02:30
 * @Version 1.0
 **/
@Service
public class CoordFeedbackServiceImpl implements CoordFeedbackService {
    @Autowired
    CoordFeedbackMapper coordFeedbackMapper;
    @Override
    public String insert(CoordFeedback coordFeedback) {
        String uid = UUID.randomUUID().toString();
        coordFeedback.setUid(uid);
        coordFeedback.setDelFlag("0");
        coordFeedback.setCreateTime(new Date());
        coordFeedbackMapper.insert(coordFeedback);
        return uid;
    }

    @Override
    public Integer update(CoordFeedback coordFeedback) {
        coordFeedback.setUpdateTime(new Date());
        return coordFeedbackMapper.update(coordFeedback);
    }

    @Override
    public Integer  delete(String uid) {
        return coordFeedbackMapper.delete(uid);
    }
    @Override
    public Integer batchDelete(String[] uids) {
            return coordFeedbackMapper.batchDelete(uids);
    }

    @Override
    public CoordFeedback get(String uid) {
        return coordFeedbackMapper.get(uid);
    }

    @Override
    public List<CoordFeedback> list(CoordFeedback coordFeedback) {
    return  coordFeedbackMapper.list(coordFeedback);
    }

    @Override
    public PageInfo<CoordFeedback> getPagingData(int offset, int limit,String orderBy, CoordFeedback coordFeedback) {
        if(null==orderBy|| StringUtils.isBlank(orderBy)){
        PageHelper.startPage((offset/limit)+1,limit);
        }else{
        PageHelper.startPage((offset/limit)+1,limit,orderBy);
        }
        PageInfo<CoordFeedback> pageInfo =new PageInfo<>(coordFeedbackMapper.list(coordFeedback));
            return pageInfo;
            }
    @Override
    public String insertOrUpdate(CoordFeedback coordFeedback){
        if(null!=coordFeedback.getUid()){
            this.update(coordFeedback);
        }else{
            this.insert(coordFeedback);
        }
        return coordFeedback.getUid();
    }
            }
